<%@ page contentType="text/html;charset=UTF-8" language="java" trimDirectiveWhitespaces="true" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="format-detection" content="email=no">
    <title>荩美国际商城</title>
    <link href="/resources/frontcss/cart.css" rel="stylesheet">
    <script src="/resources/js/jquery-1.8.1.min.js" type="text/javascript"></script>
    <style>
        .top-cot{ width:100%; height:2.2rem; line-height:2.2rem; background:#28163d; color:#fff; text-align:center; font-size:16px;}
    </style>
</head>
<body style="background-color: #fff;overflow-x:hidden;">
<div class="top-cot">我的资金</div>
<div class="total-list2 clearfix">

    <ul>
        <li class="good-center2" >
            <p class="fl price">可用资金:<span class="single_price" id="cash">${money.cash}</span></p>
        </li>
    </ul>
    <ul>
        <li class="good-center2" >
            <p class="fl price">购物币:<span class="single_price" id="bonus">${money.bonus}</span></p>
        </li>
    </ul>
    <ul>
        <li class="good-center2" >
            <p class="fl price">现金币与购物币兑换比例:<span class="single_price">1:<span id="bl">${transferAmout}</span></span></p>
        </li>
    </ul>


    <div class="takeinfo" style="">
        <label>
            <input type="text" name="amount" id="amount" value="" class="info-response-width" placeholder="请输入要兑换的购物币金额" onkeyup="showTransfer()">
        </label><br>
        <label>
            <input type="text" name="remark" id="remark" value="" class="info-response-width" placeholder="备注">
        </label><br>
        <label id="msg">

        </label>
     </div>

    <div class="cart-bottom">
        <button id="order_add_submit2" onclick="submit()">转账</button>
    </div>
</div>
<script type="text/javascript">
    function showTransfer(){
        var amount = $("#amount").val();
        if(amount!=''){
            if(!isNaN(amount)){
                var cash = parseFloat(amount)/parseFloat($("#bl").html());
                $("#msg").html("可兑换现金币："+cash);
            }
        }
    }
    function submit(){
        var amount = $("#amount").val();
        if(isNaN(amount)){
            alert("转账金额请输入数字格式！");
            return ;
        }
        var cash = parseFloat($("#bonus").html());
        if(parseFloat(amount)>cash){
            alert("输入的金额不能超过购物币金额！");
            return ;
        }
        $.ajax({
            url:"/front/user/amount/transfer?r="+Math.random(),
            type:"post",
            data: {
                amount:amount,
                remark:$("#remark").val()
            },
            success:function (res) {
                alert(res.msg);
                if(res.success){
                    window.location.href = "/front/user/main";
                }
            },
            error:function () {

            }
        }
        )
    }
</script>
</body>
</html>